import {Service} from "adajs";
import Input from "./../../../controls/form/input";
import Select from "./../../../controls/form/select";
import Username from "./../../../controls/form/username";
import ReasonSelect from "./../../../controls/form/reasonselect";
import User from "./../../../lib/user";

class LodgeService extends Service {
    defaultData() {
        if (!User.isAdmin()) {
            return {
                title: "设置",
                form: {
                    fields: [
                        {type: Input, name: "goDate", label: "出国（境）时间", inputType: "date", required: true},
                        {type: Input, name: "backDate", label: "返回时间", inputType: "date", required: true},
                        {type: Input, name: "destination", label: "目的地", inputType: "text", required: true},
                        {type: ReasonSelect, name: "reason", label: "事由", inputType: "text", required: true},
                        {
                            type: Select, name: "cgjzj", label: "出国境是否交由组织统一管理", options: [
                                {name: "是", value: 0},
                                {name: "否", value: 1}
                            ]
                        }
                    ],
                    btns: [
                        {action: "submit", name: "提交"}
                    ]
                }
            };
        } else {
            return {
                title: "设置",
                form: {
                    fields: [
                        {type: Username, name: "sqrid", label: "姓名", required: true},
                        {type: Input, name: "goDate", label: "出国（境）时间", inputType: "date", required: true},
                        {type: Input, name: "backDate", label: "返回时间", inputType: "date", required: true},
                        {type: Input, name: "applyTime", label: "申请时间", inputType: "date", required: true},
                        {type: Input, name: "destination", label: "目的地", inputType: "text", required: true},
                        {type: ReasonSelect, name: "reason", label: "事由", inputType: "text", required: true},
                        {
                            type: Select, name: "cgjzj", label: "出国境是否交由组织统一管理", options: [
                                {name: "是", value: 0},
                                {name: "否", value: 1}
                            ]
                        }
                    ],
                    btns: [
                        {action: "submit", name: "提交"}
                    ]
                }
            };
        }
    }

    onupdate(current, data) {
        Object.assign(current, data);
    }
}

export default LodgeService;